package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author:石小俊
 * @Date:2022/12/12 9:25
 * @Version:1.0-SNAPSHOT
 * @Description: 通配符配置
 *  只要请求以/test开头,均可以访问当前Servlet
 */
@WebServlet("/test/*")
public class TestServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();

        String path = request.getServletPath();
        // 此时path的值只有/test
        System.out.println("servletPath:"+path);

        out.print("<h1 style='color:green;'>这是第一种通配符的使用方式</h1>");
    }
}
